package mywebapp.tools.jsf;

import mywebapp.impl.*;
import mywebapp.dao.*;
import mywebapp.webpage.*;
import mywebapp.dao.visiteur.VisiteurModelJava;

public class FACES_GENERATION_JSF
{
  protected static String nl;
  public static synchronized FACES_GENERATION_JSF create(String lineSeparator)
  {
    nl = lineSeparator;
    FACES_GENERATION_JSF result = new FACES_GENERATION_JSF();
    nl = null;
    return result;
  }

  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + NL + "" + NL + "<faces-config" + NL + "    xmlns=\"http://java.sun.com/xml/ns/javaee\"" + NL + "    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + NL + "    xsi:schemaLocation=\"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd\"" + NL + "    version=\"1.2\">" + NL + "\t<!-- Les Beans -->" + NL + "\t";
  protected final String TEXT_2 = NL + "\t<managed-bean>" + NL + "\t\t<managed-bean-name>";
  protected final String TEXT_3 = "</managed-bean-name>" + NL + "\t\t<managed-bean-class>";
  protected final String TEXT_4 = ".model.";
  protected final String TEXT_5 = "</managed-bean-class>" + NL + "\t\t<managed-bean-scope>none</managed-bean-scope>" + NL + "\t</managed-bean>" + NL + "\t" + NL + "\t";
  protected final String TEXT_6 = "\t" + NL + "\t" + NL + "\t$$CONTROLLER$$" + NL + "\t" + NL + "\t$$NAVIGATION$$" + NL + "\t" + NL + "\t$$VALIDATOR$$" + NL + "</faces-config>";
  protected final String TEXT_7 = NL;

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
     WebAppImpl webapp = (WebAppImpl) argument; 
    stringBuffer.append(TEXT_1);
    
	for(Object oEntity : webapp.getEntities())
	{
		Entity e = (Entity) oEntity;
	
    stringBuffer.append(TEXT_2);
    stringBuffer.append( VisiteurModelJava.syntaxeParam(e.getName()) );
    stringBuffer.append(TEXT_3);
    stringBuffer.append( VisiteurModelJava.syntaxeParam(webapp.getName()));
    stringBuffer.append(TEXT_4);
    stringBuffer.append( VisiteurModelJava.syntaxeSetGetParam(e.getName()));
    stringBuffer.append(TEXT_5);
    }
    stringBuffer.append(TEXT_6);
    stringBuffer.append(TEXT_7);
    return stringBuffer.toString();
  }
}
